import { TOKEN } from "./auth";
import request, { baseUrl } from "./httpInterceptor";
import { Toast } from "./uniHooks/toast";

/** 附件表API-上传单个附件 */
export const postAttachmentTempUpload = (params: File| any, url) => {
  return new Promise((r, j) => {
    const uploadTask = uni.uploadFile({
      url: url || `${baseUrl}/attachment/temp/upload`,
      filePath:
	  params,
      name: "file",
      // formData: params || {},
      header: {
        Authorization: TOKEN(),
      },
      success: (uploadFileRes) => {
        r(JSON.parse(uploadFileRes.data));
        Toast("上传成功");
      },
	  complete:()=>{
		uni.hideLoading()
	  }
	  
    });
    uploadTask.onProgressUpdate((res) => {
      console.log("上传进度" + res.progress);
      console.log("已经上传的数据长度" + res.totalBytesSent);
      console.log("预期需要上传的数据总长度" + res.totalBytesExpectedToSend);
      // 测试条件，取消上传任务。
      // if (res.progress > 50) {
      // 	uploadTask.abort();
      // }
    });
  });
};
